package org.lgiavedoni.android.franq.command.general;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.lgiavedoni.android.franq.core.command.Command;
import org.lgiavedoni.android.franq.core.speak.CommonPhraseHelper;
import org.lgiavedoni.android.franq.service.communication.CommunicationService;
import org.lgiavedoni.android.franq.service.prediction.PredictionService;

public class PredictionCommand extends Command {

	private static final String OPTION_CREATE = "create";
	private static final String OPTION_PREDICTIONS = "predictions";
	private static final String OPTION_RULES = "rules";

	@Override
	public void setOptions(Options options) {
		options.addOption(OPTION_CREATE, true, "Create new Predictions/Rules");
	}

	@Override
	public boolean execute(CommandLine cmd) {
		if (cmd.hasOption(OPTION_CREATE)) {
			if (cmd.getOptionProperties(OPTION_CREATE).containsKey(OPTION_PREDICTIONS)) {
				PredictionService.inst.generatePredictions();
				CommunicationService.inst.sendMessage(CommonPhraseHelper.DONE);
				return true;
			}
			if (cmd.getOptionProperties(OPTION_CREATE).containsKey(OPTION_RULES)) {
				PredictionService.inst.updatePredictionRules();
				CommunicationService.inst.sendMessage(CommonPhraseHelper.DONE);
				return true;
			}
		}
		return false;
	}

	@Override
	public String getCommandText() {
		return "prediction";
	}
}